<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <title></title>
    <meta charset="UTF-8">
   <link rel="stylesheet" type="text/css" href="/ncrm/Public/Admin/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="/ncrm/Public/Admin/css/bootstrap-responsive.css">
    <link rel="stylesheet" type="text/css" href="/ncrm/Public/Admin/css/style.css">
    <style type="text/css">
        body {
            padding-bottom: 40px;
        }
        .sidebar-nav {
            padding: 9px 0;
        }

        @media (max-width: 980px) {
            /* Enable use of floated navbar text */
            .navbar-text.pull-right {
                float: none;
                padding-left: 5px;
                padding-right: 5px;
            }
        }
        #bg{width:100%;height:100%;top:0px;left:0px;position:absolute;filter: Alpha(opacity=50);opacity:0; background:#000000; display:none;}
       #popbox{position:absolute;width:200px; height:200px; left:55%; top:60%; margin:-200px 0 0 -200px; display:none;}
    </style>
   
<script src="/ncrm/Public/Admin/js/b5m.js" charset="utf-8" id="b5mmain" type="text/javascript"></script>
<link type="text/css" href="/ncrm/Public/Admin/css/b5m-plugin.css" rel="stylesheet">
<link type="text/css" href="/ncrm/Public/Admin/css/b5m.css" rel="stylesheet">
</head>
<body>
<table class="table table-bordered table-hover definewidth m10">
   <tbody>
   <!-- 几区管理开始 -->
      <tr>
    	<td width="100px">区管理：</td>
        <td style="text-align:left;">
            <input id="adddepartmentid" placeholder="请输入新增区名称">&nbsp;&nbsp;&nbsp;
            <input value="新增区" onclick="addDepartment()" class="btn btn-primary" type="button">
        </td>
    	<td style="text-align:left;">
          <select name="" id="deletedepartid">
             <option selected="selected" value="-1">请选择区</option>
             <?php if(is_array($bumen)): $i = 0; $__LIST__ = $bumen;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$r): $mod = ($i % 2 );++$i;?><option value="<?php echo ($r["did"]); ?>"><?php echo ($r["dname"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?> 
          </select>

           <input value="删除区" onclick="deleteDepartment()" class="btn btn-primary" type="button">
         </td>	
    	</tr>
      <!-- 几区管理结束 -->
      <!-- 总经理管理开始 -->
      <tr>
         <td>总经理管理：</td>
          <td style="text-align:left;">
            <select name="" id="managerdepartidzongjingli">
               <option selected="selected" value="-1">请选择区</option>
               <?php if(is_array($bumen)): $i = 0; $__LIST__ = $bumen;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$r): $mod = ($i % 2 );++$i;?><option value="<?php echo ($r["did"]); ?>"><?php echo ($r["dname"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
           </select>
           <input placeholder="请输入员工的登录帐号" id="manageridzongjingli">
           <input value="新增总经理" onclick="addManager()" class="btn btn-primary" type="button"><font>(总经理的登陆账号)</font>
         </td>
         <td style="text-align:left;">
             <select name="" id="employeeid">
              <option selected="selected" value="-1">区总经理</option>
              <?php if(is_array($zjl)): $i = 0; $__LIST__ = $zjl;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$q): $mod = ($i % 2 );++$i;?><option value="<?php echo ($q["userid"]); ?>"><?php echo ($q["username"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
             </select>
            <input onclick="deleteManager()" value="删除总经理" class="btn btn-primary" type="button">
          </td>
      </tr>
      <!-- 总经理管理结束 -->
      <!-- 总监管理开始 -->
      <tr>
         <td>总监管理：</td>       
          <td style="text-align:left;">
            <select name="" id="managerdepartid1">
               <option selected="selected" value="-1">请选择区</option>
               <?php if(is_array($bumen)): $i = 0; $__LIST__ = $bumen;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$r): $mod = ($i % 2 );++$i;?><option value="<?php echo ($r["did"]); ?>"><?php echo ($r["dname"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
           </select>
           <select name="sector" id="sector1">
              <option selected="selected" value="-1">请选择部门</option>
              <option value="1">一部</option>
              <option value="2">二部</option>
              <option value="3">三部</option>
           </select>

           <input placeholder="请输入员工的登录帐号" id="managerid1">
           <input value="新增总监" onclick="addzongjian()" class="btn btn-primary" type="button"><font>(总监的登陆账号)</font>
         </td>
         <td style="text-align:left;">
             <select name="" id="deletezongjian">
              <option selected="selected" value="-1">部门总监</option>
              <?php if(is_array($zj)): $i = 0; $__LIST__ = $zj;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$w): $mod = ($i % 2 );++$i;?><option value="<?php echo ($w["userid"]); ?>"><?php echo ($w["username"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
             </select>
            <input onclick="deleteZongJian()" value="删除总监" class="btn btn-primary" type="button">
          </td>
      </tr>
      <!-- 总监管理结束 -->      
      <!-- 经理管理开始 -->      
      <tr>
         <td>经理管理：</td>       
          <td style="text-align:left;">
            <select name="jingliqu" id="jingliqu">
               <option selected="selected" value="-1">请选择区</option>
               <?php if(is_array($bumen)): $i = 0; $__LIST__ = $bumen;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$r): $mod = ($i % 2 );++$i;?><option value="<?php echo ($r["did"]); ?>"><?php echo ($r["dname"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
           </select>
           <select name="jinglibumen" id="jinglibumen">
              <option selected="selected" value="-1">请选择部门</option>
              <option value="1">一部</option>
              <option value="2">二部</option>
              <option value="3">三部</option>
           </select>
           <select name="jinglizu" id="jinglizu">
              <option selected="selected" value="-1">请选择组</option>
              <option value="1">一组</option>
              <option value="2">二组</option>
              <option value="3">三组</option>
           </select>        

           <input placeholder="请输入员工的登录帐号" id="addjingli">
           <input value="新增经理" onclick="addjingli()" class="btn btn-primary" type="button"><font>(经理的登陆账号)</font>
         </td>
         <td style="text-align:left;">
             <select name="" id="deletejingli">
              <option selected="selected" value="-1">部门经理</option>
              <?php if(is_array($jl)): $i = 0; $__LIST__ = $jl;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$e): $mod = ($i % 2 );++$i;?><option value="<?php echo ($e["userid"]); ?>"><?php echo ($e["username"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
             </select>
            <input onclick="deleteJianLi()" value="删除经理" class="btn btn-primary" type="button">
            
          </td>
      </tr>
      <!-- 经理管理结束 -->      
      <!-- 主任管理开始 -->      
      <tr>
         <td>主任管理：</td>       
          <td style="text-align:left;">
            <select name="zurenqu" id="zhurenqu">
               <option selected="selected" value="-1">请选择区</option>
               <?php if(is_array($bumen)): $i = 0; $__LIST__ = $bumen;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$r): $mod = ($i % 2 );++$i;?><option value="<?php echo ($r["did"]); ?>"><?php echo ($r["dname"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
           </select>
           <select name="zurenbumen" id="zhurenbumen">
              <option selected="selected" value="-1">请选择部门</option>
              <option value="1">一部</option>
              <option value="2">二部</option>
              <option value="3">三部</option>
           </select>
           <select name="zurenzu" id="zurenzu">
              <option selected="selected" value="-1">请选择组</option>
              <option value="1">一组</option>
              <option value="2">二组</option>
              <option value="3">三组</option>
           </select>
           <select name="zurendui" id="zhurendui">
              <option selected="selected" value="-1">请选择队</option>
              <option value="1">一队</option>
              <option value="2">二队</option>
              <option value="3">三队</option>
           </select> 

           <input placeholder="请输入员工的登录帐号" id="zhurenval">
           <input value="新增主任" onclick="addZhuren()" class="btn btn-primary" type="button"><font>(主任的登陆账号)</font>
         </td>
         <td style="text-align:left;">
             <select name="" id="deleteZhuRen">
              <option selected="selected" value="-1">小组主任</option>
              <?php if(is_array($zr)): $i = 0; $__LIST__ = $zr;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$d): $mod = ($i % 2 );++$i;?><option value="<?php echo ($d["userid"]); ?>"><?php echo ($d["username"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
             </select>
            <input onclick="deleteZhuRen()" value="删除主任" class="btn btn-primary" type="button">
            
          </td>
      </tr>
      <!-- 主任管理结束 -->

    </tbody>
  </table>
   <a href="#" onclick="pupopen()"></a>
       <div id="bg"></div>
       <div id="popbox">
          <img src="/ncrm/Public/Admin/images/loading.gif">
          <a href="#"  onclick="pupclose()"></a>
      </div>
</body>
    <script type="text/javascript" src="/ncrm/Public/Admin/js/jquery.js"></script>
    <!--<script type="text/javascript" src="Js/jquery.sorted.js"></script>-->
    <script type="text/javascript" src="/ncrm/Public/Admin/js/bootstrap.js"></script>
    <script type="text/javascript" src="/ncrm/Public/Admin/js/ckform.js"></script>
    <script type="text/javascript" src="/ncrm/Public/Admin/js/common.js"></script>
    <script type="text/javascript">
     function pupopen(){
          document.getElementById("bg").style.display="block";
          document.getElementById("popbox").style.display="block" ; 
    }

    function pupclose(){
          document.getElementById("bg").style.display="none";
          document.getElementById("popbox").style.display="none" ;  
    }
</script>
    <script type="text/javascript">
    /*----------添加区--------------*/
        function addDepartment(){
            var departmentname=$("#adddepartmentid").val();
            if(departmentname==""){
                alert("请输入新增区名称");
                return false;
            }
            var r=confirm("是否新增？");
            if(r){
                   $.ajax({
                    type: 'POST',
                    url: "<?php echo U('Group/addBuMen');?>",
                    data: {departmentname:departmentname},
                    dataType : "json", 
                    success: function(data) {
                        if(data.ok==1){
                                alert("新增成功");
                                $("#adddepartmentid").val("");
                                window.location.reload();
                             }
                        if(data.ok==2){
                                 alert("新增失败,请稍后重试");
                            }
                         
                      }
                   })
               }
         }
         /*-----------------删除区--------------------*/
        function deleteDepartment(){
            var departmentdid=$("#deletedepartid").val();
            if(departmentdid==-1){
                alert("请选择要删除的区");
                return false;
            }
            var r=confirm("是否删除区？");
            if(r){

                 $.ajax({
                    type: 'POST',
                    url: "<?php echo U('Group/delBumen');?>",
                    data: {did:departmentdid},
                    dataType : "json", 
                    success: function(data) {
                        if(data.ok==0){
                            alert("该区下有成员，不能删除！");
                            return false;
                        }
                        if(data.ok==1){
                           alert("删除成功");
                           window.location.reload();
                        }
                        if(data.ok==2){
                           alert("删除失败,请稍后重试");
                        }
                         
                      }
                   })
            }
        }
        /*----------------删除总经理----------------*/
        function deleteManager(){
            var userid=$("#employeeid").val();
            if(userid==-1){
                alert("请选择要删除的总经理");
                return false;
            }
            var run = confirm("是否删除总经理?");
            if(run){
                pupopen();
                 $.ajax({
                    type: 'POST',
                    url: "<?php echo U('Group/delJingLi');?>",
                    data: {userid:userid},
                    dataType : "json", 
                    success: function(data) {
                        pupclose();
                        if(data.ok==1){
                            alert("删除成功");
                            $("#employeeid").val(-1);
                            window.location.reload();
                        }
                         if(data.ok==2){
                            alert("删除失败,请稍后重试");
                            $("#employeeid").val(-1);
                        }
                        if(data.ok==0){
                            alert("删除失败,没有此帐号！");
                            $("#employeeid").val(-1);
                         
                         }
                      }
                   })               
            }
        }

        /**********************删除总监*****************/
        function deleteZongJian(){
            var userid=$("#deletezongjian").val();
            if(userid==-1){
                alert("请选择要删除的总监");
                return false;
            }
            var run = confirm("是否删除总监?");
            if(run){
                pupopen();
                 $.ajax({
                    type: 'POST',
                    url: "<?php echo U('Group/delZongJian');?>",
                    data: {userid:userid},
                    dataType : "json", 
                    success: function(data) {
                        pupclose();
                        if(data.ok==1){
                            alert("删除成功");
                            $("#employeeid").val(-1);
                            window.location.reload();
                        }
                         if(data.ok==2){
                            alert("删除失败,请稍后重试");
                            $("#employeeid").val(-1);
                        }
                        if(data.ok==0){
                            alert("删除失败,没有此帐号！");
                            $("#employeeid").val(-1);
                         
                         }
                      }
                   })               
            }
        }

        /***********************删除经理****************/
        function deleteJianLi(){
            var userid=$("#deletejingli").val();
            if(userid==-1){
                alert("请选择要删除的经理");
                return false;
            }
            var run = confirm("是否删除经理?");
            if(run){
                pupopen();
                 $.ajax({
                    type: 'POST',
                    url: "<?php echo U('Group/delJingLi2');?>",
                    data: {userid:userid},
                    dataType : "json", 
                    success: function(data) {
                        pupclose();
                        if(data.ok==1){
                            alert("删除成功");
                            $("#employeeid").val(-1);
                            window.location.reload();
                        }
                         if(data.ok==2){
                            alert("删除失败,请稍后重试");
                            $("#employeeid").val(-1);
                        }
                        if(data.ok==0){
                            alert("删除失败,没有此帐号！");
                            $("#employeeid").val(-1);
                         
                         }
                      }
                   })               
            }
        }

        /***********************删除主任***************/
        function deleteZhuRen(){
            var userid=$("#deleteZhuRen").val();
            if(userid==-1){
                alert("请选择要删除的主任");
                return false;
            }
            var run = confirm("是否删除主任?");
            if(run){
                pupopen();
                 $.ajax({
                    type: 'POST',
                    url: "<?php echo U('Group/delZhuRen');?>",
                    data: {userid:userid},
                    dataType : "json", 
                    success: function(data) {
                        pupclose();
                        if(data.ok==1){
                            alert("删除成功");
                            $("#employeeid").val(-1);
                            window.location.reload();
                        }
                         if(data.ok==2){
                            alert("删除失败,请稍后重试");
                            $("#employeeid").val(-1);
                        }
                        if(data.ok==0){
                            alert("删除失败,没有此帐号！");
                            $("#employeeid").val(-1);
                         
                         }
                      }
                   })               
            }
        }

        /*----------------添加总经理-------------------*/
        function addManager(){
            var loginname=$("#manageridzongjingli").val();
            var departmentid=$("#managerdepartidzongjingli").val();
            if(departmentid==-1){
                alert("请选择部门");
                return false;
            }
            if(loginname==""){
                alert("员工的登陆账号不能为空");
                return false;
            }
            var run = confirm("是否增加总经理?");
            if(run){
                 $.ajax({
                    type: 'POST',
                    url: "<?php echo U('Group/addJingLi');?>",
                    data: {'loginName':loginname,'did':departmentid},
                    dataType : "json", 
                    success: function(data) {
                        if(data.ok==0){
                            alert("该员工已是总经理！");
                            $("#manageridzongjingli").val("");
                            $("#managerdepartidzongjingli").val(-1);
                        }
                        if(data.ok==1){
                                alert("新增成功");
                                $("#manageridzongjingli").val("");
                                window.location.reload();
                        }
                        if(data.ok==2){
                            alert("没有此帐号！");
                            $("#manageridzongjingli").val("");
                            $("#managerdepartidzongjingli").val(-1);
                        }
                        if(data.ok==3){
                            alert("添加失败！");
                            $("#manageridzongjingli").val("");
                            $("#managerdepartidzongjingli").val(-1);
                        } 
                      }
                   })       
            }
        }

        /*******************添加总监******************/

        function addzongjian()
        {
          var addzongjianqu = $('#managerdepartid1').val();
          var addzongjianbu = $('#sector1').val();
          var addzongjianname = $("#managerid1").val();

          if(addzongjianqu == -1 ){
            alert('请选择区');
            return false;
          }
          if(addzongjianbu == -1){
            alert('请选择部门');
            return false;
          }
          if(addzongjianname == ""){
            alert('请输入总监的登录帐号');
            return false;
          }
          var action = confirm('是否增加总监');
          if(action){
            $.ajax({
              url:"<?php echo U('Group/addzongjian');?>",
              type:"post",
              dataType:'json',
              data:{'addzongjianqu':addzongjianqu,'addzongjianbu':addzongjianbu,'addzongjianname':addzongjianname},
              success:function(data){
                      if(data.ok==0){
                            alert("该员工已是总监！");
                            $("#managerdepartid1").val(-1);
                            $("#sector1").val(-1);
                        }
                        if(data.ok==1){
                                alert("新增成功");
                                $("#managerdepartid1").val(-1);
                                $("#sector1").val(-1);
                                window.location.reload();
                        }
                        if(data.ok==3){
                            alert("没有此帐号！");
                            $("#managerdepartid1").val(-1);
                            $("#sector1").val(-1);
                        }
                        if(data.ok==2){
                            alert("添加失败！");
                            $("#managerdepartid1").val(-1);
                            $("#sector1").val(-1);
                      } 
              }
            })
          }
        }

        /************添加经理*********/

        function addjingli()
        {
          var quid = $("#jingliqu").val();
          var bumenid = $("#jinglibumen").val();
          var jinglizu = $("#jinglizu").val();
          var jingli = $("#addjingli").val();

          if(quid == -1){
            alert('请选择区');
            return false;
          }
          if(bumenid == -1){
            alert("请选择部门");
            return false;
          }
          if(jinglizu == -1){
            alert('请选择组');
            return false;
          }
          if(jingli == ''){
            alert('请输入员工的登录帐号');
            return false;
          }

          var action = confirm('是否添加经理');
          if(action){
            $.ajax({
            url:"<?php echo U('Group/addJingLi2');?>",
            type:"post",
            dataType:'json',
            data:{'quid':quid,'bumenid':bumenid,'jinglizu':jinglizu,'jingli':jingli},
            success:function(data){
              if(data.ok == 0){
                alert('该成员已经是经理');
              }
              if(data.ok == 1){
                alert('添加成功');
              }
              if(data.ok == 2)
              {
                alert('添加失败');
              }
              if(data.ok == 3){
                alert('没有该员工');
              }
            }
            })
          }
        }

        /************添加主任************/
        function addZhuren()
        {
          var quid = $("#zhurenqu").val();
          var bumenid = $("#zhurenbumen").val();
          var zuid = $('#zurenzu').val();
          var zurendui = $('#zhurendui').val();
          var zhuren = $('#zhurenval').val();
          if(quid == -1)
          {
            alert('请选择区');
            return false;
          }
          if(bumenid == -1){
            alert('请选择部门');
            return false;
          }
          if(zuid == -1)
          {
            alert('请选择组');
            return false;
          }
          if(zurendui == -1)
          {
            alert('请选择队');
            return false;
          }
          if(zhuren == '')
          {
            alert('请输入员工的登录帐号');
            return false;
          }
          var action = confirm("是否添加主任");
          if(action)
          {
            $.ajax({
            url:"<?php echo U('Group/addZhuRen');?>",
            type:"post",
            dataType:'json',
            data:{'quid':quid,'bumenid':bumenid,'zuid':zuid,'duiid':zurendui,'zhuren':zhuren},
            success:function(data)
            {
              if(data.ok == 3)
              {
                alert('没有该员工');
              }
              if(data.ok == 1)
              {
                alert('添加成功');
              }
              if(data.ok == 2)
              {
                alert('添加失败');
              }
              if(data.ok == 0)
              {
                alert('该成员已经是主任');
              }
            }
            })
          }
        }
    </script>
</html>